package seg.cd;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import stat.GaussianModel;


public class CDThetaSigma extends CornerDetector {


	public static final int multi = 2;

	public CDThetaSigma(int k, double[] rs) {
		super(k, rs);
	}

	public void filtrate() {
		double[] rhos = getRhos();

//		System.out.println("rho stat");
//		System.out.println("max = " + DoubleStat.max(rhos));
//		System.out.println("mean = " + GaussianModel.calcMean(rhos));
//		System.out.println("dev = " + GaussianModel.calcDev(rhos));
		int[] index;

		double mean = GaussianModel.calcMeanBetween(rhos, getStart(), getEnd());
		double var = GaussianModel.calcDevBetween(rhos, getStart(), getEnd());
		double ddd = mean + multi * var;

		List<Integer> ints = new ArrayList<Integer>();
		for (int i = getStart() + 1; i < getEnd(); i++) {
			if (rhos[i] > ddd) {
				ints.add(i);
			}
		}
//System.err.println(ints);
		index = new int[ints.size()];
		int ii = 0;
		for (Iterator<Integer> it = ints.iterator(); it.hasNext(); ) {
			index[ii++] = it.next();
		}

		setIndex(index);
	}
}
